package com.ffcc.fitness.base.config;

import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Sa-Token 监听器，用于监听账号登录、登出、被踢下线等事件
 */
@Slf4j
@Component
public class SaTokenListenerImpl2 implements SaTokenListener {
    
    /** 每次登录时触发 */
    @Override
    public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginParameter loginParameter) {
        log.info("用户登录成功 - loginType: {}, loginId: {}, tokenValue: {}", 
                loginType, loginId, tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...");
    }

    /** 每次注销时触发 */
    @Override
    public void doLogout(String loginType, Object loginId, String tokenValue) {
        log.info("用户注销成功 - loginType: {}, loginId: {}, tokenValue: {}", 
                loginType, loginId, tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...");
    }

    /** 每次被踢下线时触发 */
    @Override
    public void doKickout(String loginType, Object loginId, String tokenValue) {
        log.warn("用户被踢下线 - loginType: {}, loginId: {}, tokenValue: {}", 
                loginType, loginId, tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...");
    }

    /** 每次被顶下线时触发 */
    @Override
    public void doReplaced(String loginType, Object loginId, String tokenValue) {
        log.warn("用户被顶下线 - loginType: {}, loginId: {}, tokenValue: {}", 
                loginType, loginId, tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...");
    }

    /** 每次被禁用时触发 */
    @Override
    public void doDisable(String loginType, Object loginId, String service, int level, long disableTime) {
        log.warn("用户被禁用 - loginType: {}, loginId: {}, service: {}, level: {}, disableTime: {}", 
                loginType, loginId, service, level, disableTime);
    }

    /** 每次被解封时触发 */
    @Override
    public void doUntieDisable(String loginType, Object loginId, String service) {
        log.info("用户解除禁用 - loginType: {}, loginId: {}, service: {}", 
                loginType, loginId, service);
    }

    /** 每次打开二级认证时触发 */
    @Override
    public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
        log.info("用户开启二级认证 - loginType: {}, tokenValue: {}, service: {}, safeTime: {}", 
                loginType, tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...", service, safeTime);
    }

    /** 每次关闭二级认证时触发 */
    @Override
    public void doCloseSafe(String loginType, String tokenValue, String service) {
        log.info("用户关闭二级认证 - loginType: {}, tokenValue: {}, service: {}", 
                loginType, tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...", service);
    }

    /** 每次创建Session时触发 */
    @Override
    public void doCreateSession(String id) {
        log.debug("创建Session - id: {}", id);
    }

    /** 每次注销Session时触发 */
    @Override
    public void doLogoutSession(String id) {
        log.debug("注销Session - id: {}", id);
    }

    /** 每次Token续期时触发 */
    @Override
    public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
        log.debug("Token续期 - tokenValue: {}, loginId: {}, timeout: {}", 
                tokenValue.substring(0, Math.min(8, tokenValue.length())) + "...", loginId, timeout);
    }

    // 查看SaTokenListener接口的实际方法签名，暂时留空以查看需要实现的方法
    
}
